package com.ctsi.flowable.rest.definition.controller;

import org.flowable.engine.ManagementService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author zhangjw
 * @Date: 2018/8/28 02:02
 * @Description:
 */
public class BaseProcessDefinitionController {

    @Autowired
    protected RepositoryService repositoryService;
    @Autowired
    protected ManagementService managementService;
    @Autowired
    protected RuntimeService runtimeService;

    protected ProcessDefinition getProcessDefinitionFromRequest(String processDefinitionId) {
        // 直接查询数据库，不查询缓存，防止出现挂起激活验证不一致
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();

        if (processDefinition == null) {
            throw new RuntimeException("can not get process definition!");
        }

        return processDefinition;
    }
}
